package com.xjy.rpc.netty.message;

import java.util.concurrent.TimeUnit;

/**
 * @description: TODO rpc请求消息封装类 优化字段 越小越好
 * @author XJY
 * @date 2024/9/29 14:29
 * @version 1.0
 */
public class RpcMessage {

    //魔术字段，用于客户端服务段消息验证
    private Short magic = 0x11;

    //0x01 request
    //0x02 response
    //消息类型位
    private Short messageType;
    //唯一请求id
    private Long requestId;

    //超时时间
    private Integer expireTime;
    //时间单位
    private TimeUnit unit;

    //消息体
    private AbstractMessageBody body;
    //消息体长度
    private Integer bodyLength;

    public RpcMessage(){}

    public RpcMessage(short messageType, Long requestId, int expireTime, TimeUnit unit, AbstractMessageBody body) {
        this.messageType = messageType;
        this.requestId = requestId;
        this.expireTime = expireTime;
        this.unit = unit;
        this.body = body;
    }

    public Short getMagic() {
        return magic;
    }

    public void setMagic(Short magic) {
        this.magic = magic;
    }

    public short getMessageType() {
        return messageType;
    }

    public void setMessageType(short messageType) {
        this.messageType = messageType;
    }

    public Long getRequestId() {
        return requestId;
    }

    public void setRequestId(Long requestId) {
        this.requestId = requestId;
    }

    public int getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(int expireTime) {
        this.expireTime = expireTime;
    }

    public TimeUnit getUnit() {
        return unit;
    }

    public void setUnit(TimeUnit unit) {
        this.unit = unit;
    }

    public AbstractMessageBody getBody() {
        return body;
    }

    public void setBody(AbstractMessageBody body) {
        this.body = body;
    }

    public Integer getBodyLength() {
        return bodyLength;
    }

    public void setBodyLength(Integer bodyLength) {
        this.bodyLength = bodyLength;
    }
}
